(function() {
	/*------------------------- 页面内容配置 -------------------------*/
	var list = {
		'wdy': {
			title:      'what',
			imgFormat:  './image/items/wdy_%s.jpg',
			iconFormat: '<div data-name="wdy_%s_icon" class="icon-btn sprite wdy_%s_icon"></div>',
			items:      [
				{id: 'sport', title: 'sport'},
				{id: 'family', title: 'family'},
				{id: 'lifestyle', title: 'lifestyle'}
			]
		},
		'display_cars': {
			title:      'display_cars',
			imgFormat:  './image/items/dis_%s.jpg',
			iconFormat: '<div data-name="dis_%s_icon" class="icon-btn sprite dis_%s_icon"></div>',
			items:      [
				{id: '911_carrera_S', title: '911_carrera_S'},
				{id: 'cayenne_turbo_s', title: 'cayenne_turbo_s'},
				{id: 'panamera_turbo_s', title: 'panamera_turbo_s'}
			],
			copy: true
		},
		'sport': {
			title:     'sport',
			imgFormat: './image/items/sport_%s.jpg',
			iconFormat: '<div data-name="car_%s_icon" class="icon-btn sprite car_%s_icon"></div>',
			items:     [
				{id: '911', title: 'sport_1'},
				{id: 'boxster', title: 'sport_2'},
				{id: 'cayman', title: 'sport_3'}
			],
			copy: true
		},
		'family': {
			title:     'family',
			imgFormat: './image/items/family_%s.jpg',
			iconFormat: '<div data-name="car_%s_icon" class="icon-btn sprite car_%s_icon"></div>',
			items:     [
				{id: 'macan', title: 'family_1'},
				{id: 'cayenne', title: 'family_2'},
				{id: 'panamera', title: 'family_3'}
			],
			copy: true
		},
		'lifestyle': {
			title: 'lifestyle',
			imgFormat: './image/items/lifestyle_%s.jpg',
			iconFormat: '<div data-name="lifestyle" class="icon-btn sprite lifestyle"></div>',
			copy: true,
			items:     [
				{id: 'travelclub', title: 'lifestyle_1', image: './image/items/events_travelclub.jpg', icon: '<div data-name="events_travelclub_icon" class="icon-btn sprite events_travelclub_icon"></div>'},
				{id: 'snowforce', title: 'snowforce', image: './image/items/events_snowforce.jpg', icon: '<div data-name="events_snowforce_icon" class="icon-btn sprite events_snowforce_icon"></div>'},
				{id: 'cinema', title: 'movie', icon: '<div data-name="cinema_btn" class="icon-btn sprite cinema_btn"></div>'},
				{id: 'driversselection', title: 'lifestyle_2'}
			]
		},
		's_a': {
			title: 'service_accessories',
			imgFormat: './image/items/s_a_%s.jpg',
			iconFormat: '<div data-name="s_a_%s_icon" class="icon-btn sprite s_a_%s_icon"></div>',
			items:     [
				{id: 'pds', title: 'goods'},
				{id: 'pfs', title: 'Financial_services'}
			]
		},
		'motorsport': {
			title: 'motorsport',
			imgFormat: './image/items/motorsport_%s.jpg',
			iconFormat: '<div data-name="motorsport_%s_icon" class="icon-btn sprite motorsport_%s_icon"></div>',
			items:     [
				{id: '24hours', title: '24hlemans'},
				{id: 'cupasia', title: 'pcca'}
			],
			copy: true
		},
		'events': {
			title: 'porsche_events',
			imgFormat: './image/items/events_%s.jpg',
			iconFormat: '<div data-name="events_%s_icon" class="icon-btn sprite events_%s_icon"></div>',
			copy: true,
			items:     [
				{id: 'travelclub', title: 'lifestyle_1'},
				{id: 'sportdriving', title: 'driving_school'},
				{id: 'snowforce', title: 'snowforce'},
				{id: 'golfclub', title: 'porsche-golf'}
			]
		}
	};
	/*------------------------- 页面内容配置 -------------------------*/
	list.getData = function(id) {
		if(!id) {
			return null;
		}

		var data = $.extend(true, {}, list[id]);
		_.each(data, function(v, k) {
			if(k == 'title') {
				data[k] = __(v);
			}
			if(k == 'copy') {
				data[k] = __(id + '-copy');
			}
			if(k == 'items') {
				var items = v;
				for(var i in items) {
					var item   = items[i];
					item.title = __(item.title);
					item.image = item.image || util.format(data.imgFormat, item.id);
					item.icon  = '<div class="show-icon-wrap">' + (item.icon || util.format(data.iconFormat, item.id, item.id)) + '</div>';
				}
				data[k] = items;
			}
		});
		return data;
	};


	var Show = function() {
		this.showID = '';
	};
	Show.prototype.onCreate = function() {
		this.$title     = this.$el.find('.left-zone>.title');
		this.$itemWrap  = this.$el.find('.right-zone');
		this.$addition  = this.$el.find('.addition');
		this.$naddition = this.$el.find('.n-addition');

		var that = this;
		this.$itemWrap.on('click', '.item', function() {
			var itemID = $(this).data('id');
			that.jump.call(that, that.showID, itemID);
		});

		// this.$el.on('click', '.header', function() {
		// 	pf.goPage('status');
		// });
	};
	Show.prototype.onShow = function(params) {
			if (params.showID=="wdy") {
				$("body").addClass("wdy");
			}else{
				$("body").removeClass("wdy");
				$('.operate-zoon').removeClass("test_drive_b_show");
			}

		if (params.showID=="motorsport") {
			// pcc2.light('on');
			$('body').addClass("on");
		}else{
			if ($('body').hasClass('on')) {
				// pcc2.light('off');
				$('body').removeClass('on')
			};
		}
		// this.$el.show();
		if(params && params.showID) {
			this.showID = params.showID;
			this.render(list.getData(params.showID));

			if(params.showID == 'wdy') {
				this.$addition.show();
				if(pcc2.connected) {
					icons.render(this.$addition.find('.home_left_two_img'), [{name: 'control_scan_w'}, {name: 'control_touch_b'}]);
				}else {
					icons.render(this.$addition.find('.home_left_two_img'), [{name: 'control_scan_b'}, {name: 'control_touch_w'}]);
				}
			}
			else {
				this.$addition.hide();
			}
		}
	};
	Show.prototype.onHide = function() {
		$("body").removeClass("wdy");
		// alert(2);
		// if ($('body').hasClass('on')) {
		// 	if (pf.overlayPage=="topic") {
		// 		// alert(1);
		// 	}else{
		// 		pcc2.light('off');
		// 	}
		// 	$('body').removeClass('on')
		// };
		// this.$el.hide();
		this.$title.empty();
		this.$itemWrap.empty();
		this.$naddition.empty().hide();
	};
	Show.prototype.render = function(data) {
		var that = this;
		if(null) {

		}else {
			this.$title.html(data.title);

			var html    = '';
			var itemTpl = '<div data-id="%s" class="item so-btn" style="background-image:url(%s)">%s<div class="sub-title">%s</div></div>';
			_.each(data.items, function(item, k) {
				html += util.format(itemTpl, item.id, item.image, item.icon||'', item.title);
			});
			this.$itemWrap.html(html);

			if(data.copy) {
				this.$naddition.html(data.copy).show();
			}
		}
	};
	Show.prototype.jump = function(showID, itemID) {
		console.log(showID, itemID);
		switch(showID) {
			case 'display_cars':
				console.log(itemID);
				switch(itemID) {
					case '911_carrera_S':
						 // $('#container').addClass('911_gt3');
						 // pcc2.light('on',1);
						 pf.overlay("features",{car_name:'911',lang_key:'911_carrera_S',tittle:"911 Carrera S",page_car:'911'});
					break;
					case 'cayenne_turbo_s':
						 // $('#container').addClass('cayenne_turbo_s');
						 // pcc2.light('on',2);
						 pf.overlay("features",{car_name:'cayenne',lang_key:'Cayenne_Turbo_S',tittle:"Cayenne Turbo S",page_car:'cayenne'});
					break;
					case 'panamera_turbo_s':
						 // $('#container').addClass('panamera_turbo_s');
						 // pcc2.light('on',3);
						 pf.overlay("features",{car_name:'panamera',lang_key:'panamera_Turbo_Executive',tittle:"Panamera Turbo S",page_car:'panamera'});
					break;
				}
			break;
			case 'wdy':
				pf.goPage('show', {showID: itemID});
				break;
			case 'sport':
			case 'family':
			case 'lifestyle':
				if (itemID=="driversselection") {
					itemID="pds";
				}else if (itemID=="cinema"){
					return pf.goPage('movie');	
				}else if(itemID == 'travelclub') {
					itemID="travel";
				}
				pf.goPage('detail', {detailID: itemID, classID: showID});
				break;
			//events
			case 'events':
				switch(itemID) {
					case 'golfclub':
						itemID="golf";
					break;
					case 'sportdriving':
						itemID="driving_school";
					break;
					case 'travelclub':
						itemID="travel";
					break;
				}
				pf.goPage('detail', {detailID: itemID, classID: showID});
			break;
			//motorsport
			case 'motorsport':
				switch(itemID) {
					case 'cupasia':
						itemID="pcca";
					break;
					case '24hours':
						itemID="lemans";
					break;
				}
				pf.goPage('detail', {detailID: itemID});
			break;
			case 's_a':
				switch(itemID) {
					case 'pds':
						itemID="pds";
					break;
					case 'pfs':
						itemID="Financial_services";
					break;
				}
				pf.goPage('detail', {detailID: itemID});
			break
			default:
				break;
		}
	};

	var show  = pf.newPage('show');
	var _show = pf.newPage('-show');
	util.extend(show, new Show());
	util.extend(_show, new Show());
})();















